﻿using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
using Desjardins.Transaction;
using Medianamik.UI.Web.Shop.Data;
using Medianamik.UI.Web.Shop.Data.Dto;
using Medianamik.UI.Web.Shop.Services;
using Medianamik.UI.Web.Shop.Presentation.Presenters;
using Medianamik.UI.Web.MVP.View;
using Medianamik.UI.Web.Shop.Services;

namespace Medianamik.UI.Web.Shop
{
    public partial class ShopOrderEdit: PageModuleViewWithPresenter<OrderEditPresenter>, IOrderEdit
    {
        public ClientProfile CurrentClientProfile;
        public Order CurrentOrder;
        public Address CurrentPaymentAddress;
        public Address CurrentDeliveryAddress;
        public PurchaseResult CurrentTransactionResult;
        public ShippingDTO CurrentShipping;
        public readonly JavaScriptSerializer Serializer = new JavaScriptSerializer();

        public string Notes
        {
            get { return NotesTextBox.Text; }
            set { NotesTextBox.Text = value; }
        }

        public DateTime? ShippedDate
        {
            get { return ShippedDateDatePicker.SelectedDate; }
            set { ShippedDateDatePicker.SelectedDate = value; }
        }

        public string ReturnUrl
        {
            get { return Pages.OrderList; }
        }

        public LinkButton SaveButton
        {
            get { return SaveButtonControl; }
        }

        public HyperLink CancelButton
        {
            get { return CancelLink; }
        }

        public Order Order
        {
            set
            {
                CurrentOrder = value;
            }
        }

        public ClientProfile ClientProfile
        {
            set { CurrentClientProfile = value; }
        }

        public string PaymentState
        {
            get { return ""; }
            set { ; }
        }

        public string DeliveryState
        {
            get { return ""; }
            set { ; }
        }

        public Address PaymentAddress
        {
            set { CurrentPaymentAddress = value; }
        }

        public Address DeliveryAddress
        {
            set { CurrentDeliveryAddress = value; }
        }

        public IEnumerable<TaxDTO> Taxes
        {
            set
            {
                _taxesRepeater.DataSource = value;
                _taxesRepeater.DataBind();                 
            }
        }

        public IEnumerable<OrderItem> OrderItems
        {
            set
            {
                _productsRepeater.DataSource = value;
                _productsRepeater.DataBind();
            }
        }

        public PurchaseResult TransactionResult
        {
            set { CurrentTransactionResult = value; }
        }

        public ShippingDTO Shipping
        {
            set
            {
                CurrentShipping = value;
            }
        }
    }

    public interface IOrderEdit : IOrderEdit<Order, 
        ClientProfile, OrderItem, Address>
    {
        PurchaseResult TransactionResult { set; }
    }
}
